package com.conferences.dao.impl;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.conferences.dao.ConferenceDAO;
import com.conferences.model.Conference;
import com.conferences.model.User;

@Repository("conferenceDAO")
public class ConferenceDAOImpl extends GenericHibernateDao<Conference>
		implements ConferenceDAO {

	@Override
	public void save(Conference conference) {
		super.save(conference);
	}
	
	@Override
	public void delete(Conference conference) {
		super.delete(conference);
	}

	@SuppressWarnings("unchecked")
	@Transactional(readOnly = true)
	@Override
	public List<Conference> list() {
		Criteria crit = getSession().createCriteria(Conference.class);
		return crit.list();
	}

	@Transactional(readOnly = true)
	@Override
	public Conference get(Long id) {
		Criteria crit = getSession().createCriteria(Conference.class);
		crit.add(Restrictions.eq("id", id));
		return (Conference) crit.uniqueResult();
	}

	@SuppressWarnings("unchecked")
	@Transactional(readOnly = true)
	@Override
	public List<Conference> list(User user) {
		Criteria crit = getSession().createCriteria(Conference.class);
		crit.add(Restrictions.eq("author", user));
		return crit.list();
	}
}
